﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using DAL;

namespace BUS
{
    public class SAN_PHAMBUS
    {
        public static void insert(SAN_PHAM sanpham)
        {
            SAN_PHAMDAL sanphamdal = new SAN_PHAMDAL();
            sanphamdal.Insert(sanpham);
        }

        public static void update(SAN_PHAM sanpham)
        {
            SAN_PHAMDAL sanphamdal = new SAN_PHAMDAL();
            sanphamdal.Update(sanpham);
        }

        public static void Delete(int id)
        {

            SAN_PHAMDAL sanphamdal = new SAN_PHAMDAL();
            sanphamdal.Delete(id);
        }

        public static SANPHAMcollection GET(string Where, int PageIndex, int PageSize,
                                        string OrderBy, string OrderDirection,
                                        out int TotalRecords)
        {

            SAN_PHAMDAL sanphamdal = new SAN_PHAMDAL();
            return sanphamdal.Get(Where, PageIndex, PageSize,
                            OrderBy, OrderDirection, out TotalRecords);
        }

        public static SANPHAMcollection GetAll()
        {
            int t = 0;
            SAN_PHAMDAL sanphamdal = new SAN_PHAMDAL();
            return sanphamdal.Get("where 1=1", 0, 10,
                sanphamcolum.TEN_SP.ToString(), "ASC", out t);

        }

        public static SAN_PHAM GetByID(int iD)
        {
            int t = 0;
            SAN_PHAMDAL sanphamdal = new SAN_PHAMDAL();
            SANPHAMcollection sanphamcollection = sanphamdal.Get("where " + sanphamcolum.MASP.ToString() + " = " + iD.ToString(), 0, 0,
                sanphamcolum.TEN_SP.ToString(), "ASC", out t);
            if (sanphamcollection.Count == 1)
                return sanphamcollection[0];
            return null;
        }

    }
}
